<template>
  <div class="content" v-cloak>
    <!-- 电脑版布局 -->
    <div v-if="deviceType == 'pc'" class="navView" v-show="!hideNav">
      <div class="navTitle">
        <!-- <img class="logo" src="@/assets/logo.png" /> -->
        <span class="projectName">{{ $store.state.projectName }}-管理平台</span>
      </div>
      <view class="navList">
        <nav-list ref="nav"></nav-list>
      </view>
    </div>
    <div v-if="deviceType == 'pc'" class="appContent">
      <div class="menu" v-if="!hideNav">
        <!-- 未读消息 -->

        <el-breadcrumb separator="/">
          <el-breadcrumb-item
            v-for="(item, index) in $route.matched"
            :to="
              item.children && item.children.length == 0
                ? { path: item.path }
                : ''
            "
            >{{ item.meta.title }}</el-breadcrumb-item
          >
        </el-breadcrumb>
        <div class="right">
          <div class="admin">
            <p>名称：{{ $store.state.userInfo.admin_username }}</p>
            <p>账号：{{ $store.state.userInfo.admin_account }}</p>
          </div>
          <el-tooltip effect="dark" content="退出登录" placement="bottom">
            <el-link :underline="false" @click="outLogin()"
              ><el-image class="quit" :src="imgs.quit" fit="cover"></el-image
            ></el-link>
          </el-tooltip>
        </div>
      </div>
      <div class="manageContent" v-if="!hideNav">
        <div class="operateView">
          <div
            @contextmenu.prevent="contextmenu($event, item)"
            class="operate"
            v-for="(item, index) in $store.state.manageTagList"
            :key="index"
          >
            <router-link :to="item">
              <el-tag
                :closable="$store.state.manageTagList.length > 1"
                size="large"
                :effect="$route.name == item.name ? 'dark' : 'plain'"
                @close.stop.prevent="
                  $store.commit('manageTagListRemove', {
                    type: 'this',
                    item,
                    route: $route,
                  })
                "
              >
                {{ item.meta.title }}
              </el-tag>
            </router-link>
          </div>
        </div>
        <div
          class="menuListK"
          :style="{ top: menu.y + 'px', left: menu.x + 'px' }"
          v-if="visible"
        >
          <ul class="menuList">
            <li
              @click="
                $store.commit('manageTagListRemove', {
                  type: 'this',
                  item: menu.item,
                  route: $route,
                })
              "
            >
              关闭页面
            </li>
            <li
              @click="
                $store.commit('manageTagListRemove', {
                  type: 'right',
                  item: menu.item,
                  route: $route,
                })
              "
            >
              关闭右侧页面
            </li>
            <li
              @click="
                $store.commit('manageTagListRemove', {
                  type: 'all',
                  route: $route,
                })
              "
            >
              关闭所有页面
            </li>
          </ul>
        </div>
      </div>
      <div class="scroll">
        <div class="pageContent">
          <router-view></router-view>
        </div>
      </div>
    </div>
    <!-- 手机版布局 -->
    <div v-if="deviceType == 'mobile'">

      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import navList from "./components/navView.vue";
import imgs from "./assets/img/import.js";
import { debounce } from "lodash";
const resizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends resizeObserver {
  constructor(callback = (args = [])) {
    callback = debounce(callback, 100);
    super(callback);
  }
};
import { colourBlend } from "./assets/public.js";

import socket from "./request/socket.js";
import api from "./request/api";

export default {
  name: "App",
  components: {
    navList,
  },
  watch: {
    visible(value) {
      if (value) {
        document.body.addEventListener("click", () => (this.visible = false));
      } else {
        document.body.removeEventListener(
          "click",
          () => (this.visible = false)
        );
      }
    },
    $route: {
      handler(to, from) {
        if (
          this.deviceType == "pc" &&
          JSON.stringify(this.$refs.nav.list).indexOf(`"name":"${to.name}"`) !=
            -1
        ) {
          this.$store.commit("manageTagListAdd", to);
          document.title = "致清坊" + to.meta.title;
        }
        this.hideNav = !!to.meta.hideNav;
      },
      deep: true,
    },
  },
  mounted: function () {
    this.hideNav = !!this.$route.meta.hideNav;
    this.colorChange("#fdd358", "--el-color-primary");
    this.colorChange("#3388FF", "--el-color-main");
    //获取设备类型
    const deviceType = this.$Fn.acquisitionDevice();
    this.$store.commit("setDeviceType", deviceType);
    this.deviceType = deviceType;
    
  },
  
  data() {
    return {
      imgs,
      menu: {
        x: 0,
        y: 0,
        item: null,
      },
      visible: false,
      hideNav: true,
      socket,
      deviceType: "pc",
      //消息
      unReadCont: 0,
      msgDialogShow: false,
      msgList: [],
    };
  },
  methods: {
    //获取维度消息
    colorChange(e, pre) {
      // 白色混合色
      const mixWhite = "#ffffff";
      // 黑色混合色
      const mixBlack = "#000000";
      const el = document.documentElement;
      el.style.setProperty(pre, e);
      // 这里是覆盖原有颜色的核心代码
      for (let i = 1; i < 10; i += 1) {
        el.style.setProperty(
          `${pre}-light-${i}`,
          colourBlend(e, mixWhite, i * 0.1)
        );
      }
      for (let i = 1; i < 10; i += 1) {
        el.style.setProperty(
          `${pre}-dark-${i}`,
          colourBlend(e, mixBlack, i * 0.1)
        );
      }
      // el.style.setProperty("--el-color-primary-dark", mix(e, mixBlack, 0.1));
    },
    outLogin() {
      this.$confirm("确定退出当前账号？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.commit("loginOut");
          this.$message.success("已退出登录");
          this.$store.commit("$navTo", "/login");
        })
        .catch((err) => {});
    },
    contextmenu(e, item) {
      if (this.$store.state.manageTagList.length <= 1) {
        return;
      }
      this.menu.x = e.pageX;
      this.menu.y = e.pageY;
      this.menu.item = item;
      this.visible = true;
    },
  },
};
</script>
<style lang="scss">
.mobileContent {
}
@import "assets/css/app.scss";

.content {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: stretch;

  .navView {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    transition: width 0.2s;
    width: 280px;
    height: 100%;
    box-shadow: 0 0 10px 0px rgba(156, 156, 156, 0.2);

    .navTitle {
      width: 100%;
      height: 80px;
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      background: #f3f3f3;
      padding: 30px 10px;
      user-select: none;

      img {
        width: 50px;
        height: 50px;
        border-radius: 10px;
      }

      .projectName {
        overflow: hidden;
        white-space: nowrap;
        font-size: 20px;
        line-height: 20px;
        margin-left: 20px;
        color: var(--el-color-primary);
        font-weight: bold;
      }
    }

    .navList {
      width: 100%;
      flex: 1;
    }
  }

  .appContent {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;

    .menu {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 80px;
      background: #f1f1f1;
      padding: 0 20px;

      .quit {
        width: 36px;
        height: 36px;
        transition: all 0.1s;

        &:hover {
          transform: translateY(-2px);
        }

        &:active {
          transform: translateY(0px);
        }
      }
      .right {
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
        align-items: center;
        .admin {
          font-weight: bold;
          padding: 0 30px;
        }
      }
    }

    .scroll {
      width: 100%;
      flex: 1;
      padding: 20px;

      .pageContent {
        min-width: 100%;
        box-shadow: 0 0 10px 0 rgba(156, 156, 156, 0.2);
        border-radius: 10px;
      }
    }
  }
}

.table {
  width: calc(100vw - 360px) !important;
  height: calc(100vh - 310px);
  min-width: 750px;

  .avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
}

.pagination {
  padding-top: 10px;
  display: flex;
  justify-content: flex-end;
}

@media screen and (max-width: 980px) {
  .table {
    width: calc(100vw - 200px) !important;
  }

  .navView {
    width: 120px !important;
  }

  .projectName {
    display: none;
  }
}

span[type="text"] {
  color: #333;
}

span[type="primary"] {
  color: var(--el-color-primary);
}

span[type="success"] {
  color: var(--el-color-success);
}

span[type="normal"] {
  color: var(--el-color-normal);
}

span[type="warning"] {
  color: var(--el-color-warning);
}

span[type="danger"] {
  color: var(--el-color-danger);
}

.el-table__header {
  .el-table__cell {
    background: #f1f1f1 !important;
  }
}

.el-form-item {
  .el-form-item__label {
    height: 40px;
    line-height: 40px;
  }
}

.el-drawer__body,
.ql-editor {
  &::-webkit-scrollbar {
    width: 3px;
    background-color: #f3f3f3;
  }

  &::-webkit-scrollbar-track {
    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    border-radius: 2em;
  }

  &::-webkit-scrollbar-track-piece {
    background-color: #fff;
    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    border-radius: 2em;
  }

  &::-webkit-scrollbar-thumb {
    background-color: #fff;
    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    border-radius: 2em;
  }

  &:hover::-webkit-scrollbar-thumb {
    background-color: #ccc;
  }
}
</style>
<style lang="scss" scoped>
.manageContent {
  width: 100%;
  height: 50px;
  background: #f9f9f9;

  .operateView {
    height: 48px !important;
    width: 100%;
    min-width: 650px;
    background: #fff;
    border-radius: 4px;
    overflow-x: scroll !important;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    padding: 0 17px;
    box-shadow: 0 0 10px 0 rgba(156, 156, 156, 0.2);

    &::-webkit-scrollbar {
      height: 4px;
      background-color: #fff;
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
    }

    &::-webkit-scrollbar-track {
      -webkit-border-radius: 2em;
      -moz-border-radius: 2em;
      border-radius: 2em;
    }

    &::-webkit-scrollbar-track-piece {
      background-color: #fff;
      -webkit-border-radius: 2em;
      -moz-border-radius: 2em;
      border-radius: 2em;
    }

    &::-webkit-scrollbar-thumb {
      background-color: #fff;
      -webkit-border-radius: 2em;
      -moz-border-radius: 2em;
      border-radius: 2em;
    }

    &:hover::-webkit-scrollbar-thumb {
      background-color: #ccc;
    }

    .operate {
      margin-right: 12px;
      box-shadow: 0px 3px 8px 0px rgba(82, 113, 244, 0.1);

      .el-tag {
        padding: 0 15px;

        span {
          font-size: 16px !important;
        }
      }
    }
  }

  .menuListK {
    position: absolute;
    background: #fff;
    margin: 0;
    background: #fff;
    position: absolute;
    list-style-type: none;
    padding: 5px 0;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 400;
    color: #333;
    box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, 0.3);

    .menuList {
      list-style-type: none;

      li {
        margin: 0;
        padding: 7px 16px;
        cursor: pointer;
        white-space: nowrap;

        &:hover {
          background: #eee;
        }
      }
    }
  }

  .scroll {
    width: 100%;
    flex: 1;
    height: calc(100vh - 120px);
  }
}

.item {
  margin-top: 10px;
  margin-right: 30px;
}

.el-dropdown {
  margin-top: 1.1rem;
}
</style>
